package com.zyd.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 黑车警告发送短信dao层
 *
 * @Author: caicaicainiaoa
 * @Date: 2019/3/27  9:34
 */
@Repository
public class BlackCarSmsInfoDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 通过area查询数据
     *
     * @param area
     * @return
     */
    public List findByArea(String area) {
        String sql = "SELECT `id`,full_name AS `name` ,mobile,area ,dr FROM zydzn_blackcar_sms_info where dr=0 AND area= ? ";
        return jdbcTemplate.queryForList(sql, area);
    }

    /**
     * 插入
     *
     * @param param
     */
    public void insert(Map<String, String> param) {
        String sql = "INSERT INTO zydzn_blackcar_sms_info (full_name, mobile, area, dr ) VALUES (? ,? ,? ,? ) ";
        jdbcTemplate.update(sql, param.get("name"), param.get("mobile"), param.get("area"), 0);
    }

    /**
     * 通过主键修改
     *
     * @param param
     */
    public void updateById(Map<String, String> param) {
        String sql="UPDATE zydzn_blackcar_sms_info SET full_name = ? ,mobile = ? ,area= ?  WHERE `id`= ? ";
        jdbcTemplate.update(sql, param.get("name"), param.get("mobile"), param.get("area"),param.get("id"));
    }

    /**
     * 根据id 伪删除
     * @param id
     */
    public void deleteById(String id) {
        String sql="UPDATE zydzn_blackcar_sms_info SET dr = 1 WHERE `id`= ? ";
        jdbcTemplate.update(sql,id);
    }

    /**
     * 根据area查询手机号
     * @param area
     * @return
     */
    public List<String> findMobileByArea(String area) {
        String sql="SELECT mobile FROM zydzn_blackcar_sms_info WHERE dr=0 AND area = ? ";
        return jdbcTemplate.queryForList(sql,String.class,area);
    }
}
